home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / smail-3.1.28 / contrib / execm / execm.c next >
Encoding:
C/C++ Source or Header  |  1990-10-23  |  2.7 KB  |  125 lines

  1. /* @(#)contrib/execm/execm.c    1.2 10/24/90 05:17:22 */
  2.  
  3. /*
  4.  * execm.c
  5.  *
  6.  * This program is a substitute for Xenix's /usr/lib/mail/execmail.
  7.  * It is for use in systems running Smail 3.  If you install this program
  8.  * as /usr/lib/mail/execmail, and then add the line "set execmail" to
  9.  * /usr/lib/mail/mailrc, then the Xenix /usr/bin/mail program will accept
  10.  * addresses of the form "user@some.domain".
  11.  *
  12.  * NOTE:  Installing this program disables the Xenix aliasing and routing
  13.  *        facilities (and Micnet).  If you really _need_ Micnet, then it
  14.  *        may be possible to configure Smail to call the original
  15.  *        execmail program.  Send me a note if you want to try it.
  16.  *
  17.  * Written by Chip Salzenberg at A T Engineering <chip@ateng.uucp>.
  18.  * Released to Usenet on 01 Dec 1987.
  19.  * Modified 25 Jul 1988 for use with Smail 3.x.
  20.  *
  21.  * Do what you want with this program.
  22.  * I'm not responsible for lost mail -- not that I expect problems. :-)
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include <signal.h>
  27.  
  28. /*
  29.  * Library functions
  30.  */
  31. extern  char    *malloc();
  32.  
  33. /*
  34.  * Globals used for getopt()
  35.  */
  36. extern  char    *optarg;
  37. extern  int     optind, opterr;
  38.  
  39. /*
  40.  * The Program
  41.  */
  42. main(argc, argv)
  43. int     argc;
  44. char    **argv;
  45. {
  46.     char    *progname = argv[0];
  47.     char    **sav;
  48.     int     sac, ch, badopts;
  49.  
  50.     /*
  51.      * Allocate memory for new arguments, and set the program name.
  52.      * Note the magic number eight; sorry.
  53.      */
  54.     if ((sav = (char **) malloc((argc + 8) * sizeof(char *))) == 0)
  55.     {
  56.         fprintf(stderr, "%s: out of memory?!\n", progname);
  57.         exit(1);
  58.     }
  59.  
  60.     sav[0] = "smail";
  61.     sac = 1;
  62.  
  63.     /*
  64.      * Translate the execmail options to Smail 3.x options.
  65.      */
  66.     badopts = 0;
  67.     while ((ch = getopt(argc, argv, "f:h:mnr")) != EOF)
  68.     {
  69.         switch (ch)
  70.         {
  71.         case 'f':       /* Who is this message from? */
  72.             sav[sac++] = "-f";
  73.             sav[sac++] = optarg;
  74.             break;
  75.  
  76.         case 'h':       /* Max hop count */
  77.             sav[sac++] = "-h";
  78.             sav[sac++] = optarg;
  79.             break;
  80.  
  81.         case 'm':       /* Include sender in alias expansion */
  82.             sav[sac++] = "-m";
  83.             break;
  84.  
  85.         case 'n':       /* Disable alias expansion */
  86.             sav[sac++] = "-n";
  87.             break;
  88.  
  89.         case 'r':       /* Remote -- via UUCP, not Micnet */
  90.             break;  /* smail doesn't understand Micnet anyway */
  91.  
  92.         default:        /* Illegal option */
  93.             ++badopts;
  94.             break;
  95.         }
  96.     }
  97.  
  98.     /*
  99.      * If invalid options or no addresses, print usage message and leave.
  100.      */
  101.     if (badopts || optind >= argc)
  102.     {
  103.         fprintf(stderr,
  104.           "usage: %s [-f from][-h hopcount][-m][-n][-r] addresses\n",
  105.           progname);
  106.         exit(1);
  107.     }
  108.  
  109.     /*
  110.      * Finish the argument list.
  111.      */
  112.     while (optind < argc)
  113.         sav[sac++] = argv[optind++];
  114.     sav[sac] = 0;
  115.  
  116.     /*
  117.      * Finally, let smail take over.
  118.      */
  119.     execv("/bin/smail", sav);
  120.     execv("/usr/bin/smail", sav);
  121.  
  122.     fprintf(stderr, "%s: can't execute smail!\n", progname);
  123.     exit(1);
  124. }
  125.